package com.gzsxy;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import io.netty.util.NettyRuntime;
import org.apache.commons.io.IOUtils;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author xiaolong
 * @version 1.0
 * @description: TODO
 * @date 2022/2/26 16:35
 */
public class text {


    static class sheng {
        private String id;
        private String name;
        private String sort;
        private List<school> children;


        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getSort() {
            return sort;
        }

        public void setSort(String sort) {
            this.sort = sort;
        }

        public List<school> getChildren() {
            return children;
        }

        public void setChildren(List<school> children) {
            this.children = children;
        }
    }


    static class school {
        private String id;
        private String name;
        private String short1;
        private String zone;
        private String order;

        public String getId() {
            return id;
        }

        public void setId(String id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getShort1() {
            return short1;
        }

        public void setShort1(String short1) {
            this.short1 = short1;
        }

        public String getZone() {
            return zone;
        }

        public void setZone(String zone) {
            this.zone = zone;
        }

        public String getOrder() {
            return order;
        }

        public void setOrder(String order) {
            this.order = order;
        }
    }


    public   String read() throws Exception {
        FileInputStream is = new FileInputStream(new File("sheng.txt"));
        String s = IOUtils.toString(is);
        JSONObject jsonObject = JSON.parseObject(s);
        JSONArray zone = jsonObject.getJSONArray("zone");
        JSONArray university = jsonObject.getJSONArray("university");
        List<sheng> shengs = JSON.parseArray(JSON.toJSONString(zone), sheng.class);
        List<school> school = JSON.parseArray(JSON.toJSONString(university), school.class);

        shengs.stream().forEach(e ->{

        });

        List<sheng> collect = shengs.stream().map(sheng -> {
            List<school> list = new ArrayList<>();
            school.stream().forEach(school1 -> {
                if (sheng.getId().equals(school1.getZone())) {
                    list.add(school1);
                }
            });
            sheng.setChildren(list);
            return sheng;
        }).collect(Collectors.toList());



        JSONObject jsonObject1 = new JSONObject();
        jsonObject1.put("data",collect);
        String s1 = jsonObject1.toJSONString();
        System.out.println(s1);


//        System.out.println(zone.toString());



        return s;
    }


    public static void main(String[] args) throws Exception {
//        text text = new text();
//        String read = text.read();



    }
}
